import {createRouter, createWebHistory} from "vue-router";


const pages = import.meta.glob('../views/**/page.js', {
    eager: true,
    import: 'default'
});

const pageComps = import.meta.glob('../views/**/index.vue');

const routes = Object.entries(pages).map(([pageJSPath, meta]) => {
    let path = pageJSPath.replace('../views', '').replace('/page.js', '');
    path = path || '/'
    const name = path.split('/').filter(Boolean).join('-') || 'index';
    const compPath = pageJSPath.replace('page.js', 'index.vue');
    return {
        path,
        name,
        component: pageComps[compPath],
        meta,
    };

})

//注意区别默认导出还是名称导出，具体查看vue3基础知识·导出·章节
const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router